package com.hiss.basic.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.hiss.basic.client.system.ISysDictService;
import com.hiss.basic.model.system.request.SysDictCreateRequest;
import com.hiss.basic.model.system.request.SysDictQueryRequest;
import com.hiss.basic.model.system.request.SysDictUpdateRequest;
import com.hiss.basic.model.system.response.SysDictQueryResponse;
import com.hiss.basic.starter.core.model.R;
import com.hiss.basic.starter.log.annotation.Log;
import com.hiss.basic.starter.log.enums.BusinessTypeEnum;
import com.mybatisflex.core.paginate.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 系统字典 controller
 */
@RestController
@RequestMapping("/sys/dict")
public class SysDictController {

    @Resource
    private ISysDictService sysDictService;

    @SaCheckPermission("sys:dict:list-page")
    @RequestMapping(value = "/list/page", method = RequestMethod.GET)
    public R<Page<SysDictQueryResponse>> listPage(SysDictQueryRequest request) {
        Page<SysDictQueryResponse> dictListPage = sysDictService.findPageList(request);
        return R.success(dictListPage);
    }

    @SaCheckPermission("sys:dict:create")
    @Log(title = "新增字典", businessType = BusinessTypeEnum.INSERT)
    @RequestMapping(value = "create", method = RequestMethod.POST)
    public R<Void> create(@RequestBody SysDictCreateRequest request) {
        sysDictService.create(request);
        return R.success();
    }

    @SaCheckPermission("sys:dict:update")
    @Log(title = "更新字典", businessType = BusinessTypeEnum.UPDATE)
    @RequestMapping(value = "update", method = RequestMethod.PUT)
    public R<Void> update(@RequestBody SysDictUpdateRequest request) {
        sysDictService.update(request);
        return R.success();
    }

    @SaCheckPermission("sys:dict:remove")
    @Log(title = "删除字典", businessType = BusinessTypeEnum.DELETE)
    @RequestMapping(value = "remove", method = RequestMethod.DELETE)
    public R<Void> remove(Long id) {
        sysDictService.remove(id);
        return R.success();
    }
}
